/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
function comprobar(){
	var name = document.getElementById("name");
	var email = document.getElementById("email");
	var password = document.getElementById("password");
	var password2 = document.getElementById("password2");
	var espacios = /^\s*$/;
	var campoNombre = /^Nombre$/;
        var correccion = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	var comentario = "";
	var error = false;
	var color;
	
	/*Mi name*/
	if(!(espacios.test(name.value))){
		color = document.getElementById("label_name");
		color.style.color = "black";
	}else{
		color = document.getElementById("label_name");
		color.style.color = "red";
	}
	if(espacios.test(name.value) || campoNombre.test(name.value)){
		comentario = comentario + "Debe rellenar el campo 'Nombre'.\n";
		color = document.getElementById("label_name");
		color.style.color = "red";
		error = true;
	}	
	/*Email*/
	if(espacios.test(email.value)){
		comentario = comentario + "Debe rellenar el campo 'Email' con su correo electr\xf3nico.\n";
		color = document.getElementById("label_email");
		color.style.color = "red";
		error = true;
	}else{
             if ( !correccion.test(email.value) ){
                alert("Error: La dirección de correo es incorrecta.");
            }else{
		color = document.getElementById("label_email");
		color.style.color = "black";
                }
            }   
	/*Crear una contrase?a y Confirmar contrase?a*/
	if(!(espacios.test(password.value)) && !(espacios.test(password2.value)) && (!(password.value == password2.value))){
		comentario = comentario + "La confirmaci\xf3n de su contrase\xf1a debe ser igual a la contrase\xf1a.\n";
		color = document.getElementById("label_password");
		color.style.color = "red";
		color = document.getElementById("label_password2");
		color.style.color = "red";
		error = true;
	}else{
		color = document.getElementById("label_password");
		color.style.color = "black";
		color = document.getElementById("label_password2");
		color.style.color = "black";
	}
	if(espacios.test(password.value)){
		comentario = comentario + "Escriba una contrase\xf1a.\n";
		color = document.getElementById("label_password");
		color.style.color = "red";
		error = true;
	}else{
		color = document.getElementById("label_password");
		color.style.color = "black";
	}
	if(espacios.test(password2.value)){
		comentario = comentario + "Escriba la confirmaci\xf3n de su contrase\xf1a.\n";
		color = document.getElementById("label_password2");
		color.style.color = "red";
		error = true;
	}else{
		color = document.getElementById("label_password2");
		color.style.color = "black";
	}
	if(!(espacios.test(password.value)) && !(espacios.test(password2.value)) && !(password.value == password2.value)){
		color = document.getElementById("label_password");
		color.style.color = "red";
		color = document.getElementById("label_password2");
		color.style.color = "red";
		error = true;
	}
	if(error){
		alert(comentario);
	}
	return !error;
}